package com.ecp.commons.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.ecp.commons.bean.Column;
import com.ecp.commons.db.GenericServiceImpl;

@Repository("columnService")
public class ColumnServiceImpl extends GenericServiceImpl<Column> implements ColumnService {
	@Override
	public List<Column> getColumnByParentIdAndIsFrontShow(int parentId, int isFrontShow,
			String orderBy) {
		List<Column> columns = null;
		StringBuilder sb = new StringBuilder(
				"select * from t_column tc where tc.parentId = ? and tc.isFrontShow = ? ");
		if (StringUtils.isBlank(orderBy)) {
			orderBy = "colorder ASC";
		}
		sb.append("order by ").append(orderBy);
		try {
			columns = this.getEntityList(sb.toString(), new Object[] { parentId, isFrontShow });
		} catch (Exception e) {
			columns = new ArrayList<Column>();
			e.printStackTrace();
		}
		return columns;
	}
}
